package L2iob;

import java.io.*;
import java.sql.Struct;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class StudentsManager {
    public void Add_Students(String number,String name,String sex) {
        BufferedWriter bufferedWriter = null;
        try {
            String  str =number+" "+name+" "+sex;
            bufferedWriter = new BufferedWriter(new FileWriter("./src/main/resource/test.txt", true));
            bufferedWriter.write(str);
            bufferedWriter.newLine();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
           if (bufferedWriter!=null){
               try {
                   bufferedWriter.close();
               } catch (IOException e) {
                   e.printStackTrace();
               }
           }
        }
    }

    public void Read_Students(){
        BufferedReader read = null;
        try {
            read = new BufferedReader(new FileReader("./src/main/resource/test.txt"));
            String s = null;
            while (true){
                try {
                    if (!((s = read.readLine())!=null)) break;
                } catch (IOException e) {
                    e.printStackTrace();
                }
                String [] str=s.split(" ");
                if(str.length!=1){
                    System.out.println("学号："+str[0]+"; 姓名："+str[1]+"; 性别："+str[2]);
                }
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }finally {
            if(read!=null){
                try {
                    read.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }
    }

}
